home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / castools.zip / FAXERROR.C < prev    next >
Text File  |  1990-01-11  |  4KB  |  115 lines

  1.  
  2.  
  3. /*
  4.    FAXERROR.C  The error handler for applications using the CAS Toolkit.
  5.  
  6.    This function finds information about warning or error conditions
  7.    generated by calls to the CAS Toolkit functions.
  8.  
  9.    INPUT:  Optional:  A message from the calling application, and a pointer
  10.                       to a string of warning or error information.
  11.  
  12.            Global:  The external Toolkit variables FAXerrno and CASerrorcode,
  13.                     and the external C Library variable errno.
  14.  
  15.    OUTPUT:  A string of information about the warning or error, and an
  16.             error class number (constants defined in CAS.H).
  17.  
  18.             The following table shows the error conditions checked for:
  19.  
  20.             HLT = High Level Toolkit
  21.             LLT = Low level Toolkit (CAS calls)
  22.  
  23.             HLT   LLT           Kind of error
  24.             -----------------------------------------------------
  25.               0     0           NO ERROR
  26.               0     1           CAS error from LLT function or logged event.
  27.               1     0           High-level Toolkit function only.
  28.               1     1           HLT function calling a LLT function.
  29. */
  30.  
  31. #include <string.h>
  32. #include <stdlib.h>
  33. #include <malloc.h>
  34. #include <cas.h>
  35. #include <fax.h>
  36.  
  37. char * pascal FAXError(char *MessageIn,
  38.                        char *MessageOut,
  39.                        int *ErrorClass)
  40. {
  41.   char *temp,
  42.        tempstr[MSGLENGTH];
  43.   int i;
  44.   unsigned sizeofmsg = 0;
  45.  
  46.   if (MessageOut) {                         /* It had better be big enough */
  47.     temp = MessageOut;
  48.   }
  49.   else {
  50.     temp = (char *)malloc(3*(MSGLENGTH + 1)); /* @ message plus a '\n'newline */
  51.   }
  52.   if (MessageIn) {                            /* if caller supplied a msg,    */
  53.     strncpy(temp, MessageIn, MSGLENGTH);    /* start with that */
  54.     if (temp[MSGLENGTH-1]) {
  55.       temp[MSGLENGTH-1] = '\0';
  56.     }
  57.     strcat(temp, "\n");
  58.   }
  59.   else {
  60.     temp[0] = '\0';
  61.   }
  62.  
  63.   if (FAXerrno) {                             /* If Toolkit caught an error   */
  64.     if ((FAXerrno < 0) || (FAXerrno > LASTMESSAGE)) {
  65.       FAXerrno = LASTMESSAGE;
  66.     }
  67.     strncat(temp, FAXerrlist[FAXerrno], MSGLENGTH);
  68.     strcat(temp, "\n");
  69.   }
  70.  
  71.   if (CASerrorcode) {                          /* There was a CAS error */
  72.  
  73.     if (((unsigned)(-CASerrorcode & 0xFF00) >> 8) == MULTIPLEX) {
  74.       strncat(temp, "CCAM not installed\n", MSGLENGTH);
  75.       *ErrorClass = FATALERROR;
  76.       return(temp);
  77.     }
  78.     else {
  79.       for(i=0; i<CASnerrors; i++) {
  80.         if (CASerrors[i].errorcode == CASerrorcode) {
  81.           strncat(temp, CASerrors[i].msg, MSGLENGTH);
  82.           strcat(temp, "\n");
  83.           *ErrorClass = CASerrors[i].errorclass;
  84.           return(temp);
  85.         }
  86.       }
  87.       if (i == CASnerrors) {              /* We fell through the whole list */
  88.         switch (CASerrorcode & 0xff00) {
  89.           case 0x0100: sprintf(tempstr, "DOS warning %XH\n", CASerrorcode & 0xff);
  90.                        strncat(temp, tempstr, MSGLENGTH);
  91.                        *ErrorClass = DOSWARNING;
  92.                        break;
  93.           case 0x0300: sprintf(tempstr, "DOS fatal error %XH\n", CASerrorcode & 0xff);
  94.                        strncat(temp, tempstr, MSGLENGTH);
  95.                        *ErrorClass = FATALDOSERROR;
  96.                        break;
  97.           default:     sprintf(tempstr, "%XH not a valid CAS error code\n", CASerrorcode);
  98.                        strncat(temp, tempstr, MSGLENGTH);
  99.                        *ErrorClass = UNKNOWNCASERROR;
  100.         }
  101.         return(temp);
  102.       }
  103.     }
  104.   }
  105.  
  106.   /* If we fell through the above, there was no CAS error */
  107.   if (FAXerrno) {
  108.     *ErrorClass = TOOLKITERROR;
  109.   }
  110.   else {
  111.     *ErrorClass = NOERROR;
  112.   }
  113.   return(temp);
  114. }
  115.